  
package com.xebest.web.service.impl;

import com.xebest.common.enums.erp.aftersales.VenOrderRefundStatusEnum;
import com.xebest.common.enums.erp.aftersales.VenOrderRefundTypeEnum;
import com.xebest.common.enums.erp.finance.*;
import com.xebest.common.enums.erp.order.VenOrderPayChannelEnum;
import com.xebest.common.enums.erp.order.VenOrderPayTypeEnum;
import com.xebest.common.enums.erp.order.VenOrderStatusEnum;
import com.xebest.common.enums.erp.purch.VenPurchTypeEnum;
import com.xebest.common.enums.erp.purch.VenSettlementMethodEnum;
import com.xebest.common.enums.erp.storehouse.VenStorePricingTypeEnum;
import com.xebest.common.util.XeBaseUtil;
import com.xebest.util.SysSetBeanUtils;
import com.xebest.web.controller.export.XeVenFinPurchPayExDTO;
import com.xebest.web.controller.export.XeVenFinSalesBillExDTO;
import com.xebest.web.controller.export.XeVenOrderRefundDTO;
import com.xebest.web.form.XeVenFinPurchPayForm;
import com.xebest.web.form.XeVenFinSalesBillForm;
import com.xebest.web.form.XeVenOrderRefundQueryForm;
import com.xebest.web.mapper.read.XeVenFinPurchPayCenterExportMapper;
import com.xebest.web.service.XeVenFinPurchPayCenterExportService;
import com.xebest.web.service.XeVenOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class XeVenFinPurchPayCenterExportServiceImpl implements XeVenFinPurchPayCenterExportService {

	@Autowired
	private XeVenFinPurchPayCenterExportMapper finPurchPayCenterExportMapper;

	@Autowired
	XeVenOrderService orderService;


	@Override
	public List<XeVenFinPurchPayExDTO> queryExportfinPurchPayList(XeVenFinPurchPayForm form) {
		
		List<XeVenFinPurchPayExDTO> finPurchPayExDTOList = finPurchPayCenterExportMapper.queryExportfinPurchPayList(form);
		
		for (XeVenFinPurchPayExDTO finPurchPayExDTO : finPurchPayExDTOList) {
			//采购货款状态 数字字典转字符串
			SysSetBeanUtils.codeReversionStr("psettleStatus", finPurchPayExDTO, VenPSettleStatusEnum.class);
			//驳回状态 1：正常；2：被驳回
			SysSetBeanUtils.codeReversionStr("rejectStatus", finPurchPayExDTO, VenRejectStatusEnum.class);
			//采购类型（ 1：零采 2：集采3：分拨零采）
			SysSetBeanUtils.codeReversionStr("purchType", finPurchPayExDTO, VenPurchTypeEnum.class);
			//订单状态  ：1 已完成 2 已发货 3待发货 4已取消 5 待分配 6待审核
			SysSetBeanUtils.codeReversionStr("orderStatus", finPurchPayExDTO, VenOrderStatusEnum.class);
			//结算方式（1：账期结算，2：预付款，3：现结）
			SysSetBeanUtils.codeReversionStr("settlementMethod", finPurchPayExDTO, VenSettlementMethodEnum.class);

			//拼接结算周期
			if(!StringUtils.isEmpty(finPurchPayExDTO.getSettlementTimeUnit())){
				finPurchPayExDTO.setSettlementCycle(finPurchPayExDTO.getSettlementCycle()+finPurchPayExDTO.getSettlementTimeUnit());
			}else{
				finPurchPayExDTO.setSettlementCycle(finPurchPayExDTO.getSettlementCycle());
			}
		}		
				
		return finPurchPayExDTOList;  
		
	}


	@Override
	public List<XeVenFinPurchPayExDTO> exportfinPurchPayDetail(XeVenFinPurchPayForm form) {
		List<XeVenFinPurchPayExDTO> detailList = finPurchPayCenterExportMapper.exportfinPurchPayDetail(form);
		for(XeVenFinPurchPayExDTO detail : detailList){
			//采购货款状态 数字字典转字符串
			SysSetBeanUtils.codeReversionStr("psettleStatus", detail, VenPSettleStatusEnum.class);
			//驳回状态 1：正常；2：被驳回
			SysSetBeanUtils.codeReversionStr("rejectStatus", detail, VenRejectStatusEnum.class);
			//采购类型（ 1：零采 2：集采3：分拨零采）
			SysSetBeanUtils.codeReversionStr("purchType", detail, VenPurchTypeEnum.class);
			//订单状态  ：1 已完成 2 已发货 3待发货 4已取消 5 待分配 6待审核
			SysSetBeanUtils.codeReversionStr("orderStatus", detail, VenOrderStatusEnum.class);
			//结算方式（1：账期结算，2：预付款，3：现结）
			SysSetBeanUtils.codeReversionStr("settlementMethod", detail, VenSettlementMethodEnum.class);

			//拼接结算周期
			if(!StringUtils.isEmpty(detail.getSettlementTimeUnit())){
				detail.setSettlementCycle(detail.getSettlementCycle()+detail.getSettlementTimeUnit());
			}else{
				detail.setSettlementCycle(detail.getSettlementCycle());
			}
		}
		return detailList;  
		
	}

	/**
	 * 收款单列表导出
	 */
	@Override
	public List<XeVenFinSalesBillExDTO> queryExportfinSalesBillList(XeVenFinSalesBillForm form) {
		List<XeVenFinSalesBillExDTO> finSalesBillList = finPurchPayCenterExportMapper.queryExportfinSalesBillList(form);
		for(XeVenFinSalesBillExDTO finSalesBill: finSalesBillList){
			//收款状态1：未收款2：部分收款3：已收款
			SysSetBeanUtils.codeReversionStr("sbillStatus", finSalesBill, VenSbillStatusEnum.class);
			//收款方式  1：pos:；2：微信；3：其它
			SysSetBeanUtils.codeReversionStr("sbillPayType", finSalesBill, VenSbillPayTypeEnum.class);
			//支付类型 4: 在线支付1：货到付款2：到店自提3：银行汇款 
			SysSetBeanUtils.codeReversionStr("payType", finSalesBill, VenSPayTypeEnum.class);
			//订单状态  ：1 已完成 2 已发货 3待发货
			SysSetBeanUtils.codeReversionStr("orderStatus", finSalesBill, VenSOrderStatusEnum.class);
			String area = XeBaseUtil.baseUtil.getOrgAreaName(Integer.parseInt(finSalesBill.getCaAreaId()));
			finSalesBill.setCaStreet(area+"-"+finSalesBill.getCaStreet());
			finSalesBill.setArea(area);
		}
		return finSalesBillList;  
		
	}


	@Override
	public List<XeVenFinSalesBillExDTO> queryExportfinSalesBillDetail(XeVenFinSalesBillForm form) {
		List<XeVenFinSalesBillExDTO> detailList = finPurchPayCenterExportMapper.queryExportfinSalesBillDetail(form);
		for(XeVenFinSalesBillExDTO finSalesBill: detailList){
			//收款状态1：未收款2：部分收款3：已收款
			SysSetBeanUtils.codeReversionStr("sbillStatus", finSalesBill, VenSbillStatusEnum.class);
			//收款方式  1：pos:；2：微信；3：其它
			SysSetBeanUtils.codeReversionStr("sbillPayType", finSalesBill, VenSbillPayTypeEnum.class);
			//支付类型 4: 在线支付1：货到付款2：到店自提3：银行汇款 
			SysSetBeanUtils.codeReversionStr("payType", finSalesBill, VenSPayTypeEnum.class);
			//订单状态  ：1 已完成 2 已发货 3待发货
			SysSetBeanUtils.codeReversionStr("orderStatus", finSalesBill, VenSOrderStatusEnum.class);
			String area = XeBaseUtil.baseUtil.getOrgAreaName(Integer.parseInt(finSalesBill.getCaAreaId()));
			finSalesBill.setCaStreet(area+"-"+finSalesBill.getCaStreet());
			finSalesBill.setArea(area);
		}
		return detailList;
		
	}

    /**
     * 退款单列表导出
     */
	@Override
	public List<XeVenOrderRefundDTO> exRefundOrderList(XeVenOrderRefundQueryForm form) {
		List<XeVenOrderRefundDTO> reList = finPurchPayCenterExportMapper.exRefundOrderList(form);
		for(XeVenOrderRefundDTO refundEn : reList){
			
			SysSetBeanUtils.codeReversionStr("refundType", refundEn, VenOrderRefundTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("payType", refundEn, VenOrderPayTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("refundStatus", refundEn, VenOrderRefundStatusEnum.class);
			SysSetBeanUtils.codeReversionStr("payType", refundEn, VenOrderPayTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("payChannel", refundEn, VenOrderPayChannelEnum.class);
			SysSetBeanUtils.codeReversionStr("pricingType", refundEn, VenStorePricingTypeEnum.class);

		} 
		return reList;  
		
	}


	/**
	 * 导出退款单明细
	 */
	@Override
	public List<XeVenOrderRefundDTO> exRefundOrderDetail(XeVenOrderRefundQueryForm form) {
		List<XeVenOrderRefundDTO> reDetail = finPurchPayCenterExportMapper.exRefundOrderDetail(form);
		for(XeVenOrderRefundDTO refundEn : reDetail){
			
			SysSetBeanUtils.codeReversionStr("refundType", refundEn, VenOrderRefundTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("payType", refundEn, VenOrderPayTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("refundStatus", refundEn, VenOrderRefundStatusEnum.class);
			SysSetBeanUtils.codeReversionStr("payType", refundEn, VenOrderPayTypeEnum.class);
			SysSetBeanUtils.codeReversionStr("payChannel", refundEn, VenOrderPayChannelEnum.class);
			SysSetBeanUtils.codeReversionStr("pricingType", refundEn, VenStorePricingTypeEnum.class);
		} 
		return reDetail;  
		
	}


	/**
	 * 根据收款单号查询收款单信息
	 */
	@Override
	public XeVenFinSalesBillExDTO queryExportfinSalesBillInfo(XeVenFinSalesBillForm finSales) {
		return finPurchPayCenterExportMapper.queryExportfinSalesBillInfo(finSales);  
	}

}
  
